package com.daji.statictest;

import com.daji.pojo.User;

import java.util.HashMap;
import java.util.Map;

public class StaticClass {
    private static final Map<String, User> cachedParsers = new HashMap<>();
    static {
        System.out.println("静态代码块被执行了");
        cachedParsers.put("json", new User("json"));
        cachedParsers.put("xml", new User("xml"));
        cachedParsers.put("yaml", new User("yaml"));
        cachedParsers.put("properties", new User("properties"));
    }

    public static User createParser(String configFormat) {
        if (configFormat == null || configFormat.isEmpty()) {
            return null;//返回null还是IllegalArgumentException全凭你自己说了算
        }
        User parser = cachedParsers.get(configFormat.toLowerCase());
        return parser;
    }

}
